/* 
 * File:   Box2dHingeJoint.cpp
 * Author: Elevator
 * 
 * Created on 24 Май 2013 г., 0:34
 */

#include "Box2dHingeJoint.h"
#include <Box2D/Box2D.h>

namespace physics {

	Box2dHingeJoint::Box2dHingeJoint(
		Box2dBody* bodyA, Box2dBody* bodyB,
		b2RevoluteJoint* joint )
	:
	_bodyA( bodyA ),
	_bodyB( bodyB ),
	_joint( joint ) {
	}

	Box2dHingeJoint::~Box2dHingeJoint( ) {
	}

	IBody* Box2dHingeJoint::GetBodyA( ) const {
		return _bodyA;
	}

	IBody* Box2dHingeJoint::GetBodyB( ) const {
		return _bodyB;
	}

	Vec2 Box2dHingeJoint::GetAnchorA( ) const {
		b2Vec2 anchor = _joint->GetAnchorA( );
		return Vec2( anchor.x, anchor.y );
	}

	Vec2 Box2dHingeJoint::GetAnchorB( ) const {
		b2Vec2 anchor = _joint->GetAnchorB( );
		return Vec2( anchor.x, anchor.y );
	}

	bool Box2dHingeJoint::IsLimitEnabled( ) const {
		return _joint->IsLimitEnabled( );
	}

	void Box2dHingeJoint::SetLimitEnabled( bool enableLimit ) {
		_joint->EnableLimit( enableLimit );
	}

	float Box2dHingeJoint::GetLeftLimit( ) const {
		return _joint->GetUpperLimit( );
	}

	void Box2dHingeJoint::SetLeftLimit( float leftLimit ) {
		float rightLimit = _joint->GetLowerLimit( );
		_joint->SetLimits( rightLimit, leftLimit );
	}

	float Box2dHingeJoint::GetRightLeftLimit( ) const {
		return _joint->GetLowerLimit( );
	}

	void Box2dHingeJoint::SetRightLimit( float rightLimit ) {
		float leftLimit = _joint->GetUpperLimit( );
		_joint->SetLimits( rightLimit, leftLimit );
	}

	bool Box2dHingeJoint::IsMotorEnabled( ) const {
		return _joint->IsMotorEnabled( );
	}

	void Box2dHingeJoint::SetMotorEnabled( bool enableMotor ) {
		_joint->EnableMotor( enableMotor );
	}

	float Box2dHingeJoint::GetMotorTorque( ) const {
		return _joint->GetMotorTorque( );
	}

	void Box2dHingeJoint::SetMotorTorque( float force ) {
		_joint->SetMaxMotorTorque( force );
	}

	float Box2dHingeJoint::GetMotorSpeed( ) const {
		return _joint->GetMotorSpeed( );
	}

	void Box2dHingeJoint::SetMotorSpeed( float speed ) {
		_joint->SetMotorSpeed( speed );
	}

	b2RevoluteJoint* Box2dHingeJoint::GetBox2dJoint( ) {
		return _joint;
	}
}
